package jdbc;

import java.io.*;
import java.util.Properties;

public class Pro {
    Properties root = new Properties();
    public void storePropertiesToHardFile() throws FileNotFoundException, IOException {
        Properties pro=new Properties();


        try {InputStream input = Mysq.class.getClassLoader()
                .getResourceAsStream("D:\\git_warehouse\\JAVA\\untitled2\\src\\jdbc\\config.properties");
            root.load(input);
        } catch (IOException e) {
            e.printStackTrace();
        }
        pro.setProperty("driver", "com.mysql.jdbc.Driver");
        pro.setProperty("url", "jdbc:mysql///user");
        pro.setProperty("user", "root");
        pro.setProperty("password", "451535");
        //1.通过字节流的形式
        //store(OutputStream out, String comments)
        //outputStream:字节输出流   comments：配置文件说明
        pro.store(new FileOutputStream(new File("D:\\git_warehouse\\JAVA\\untitled2\\src\\jdbc\\config1.properties")), "数据库配置文件");

        //2.通过字符流的形式
        //store(Writer writer, String comments)
        //writer:字符输出流   comments：配置文件说明
        pro.store(new FileWriter("D:\\git_warehouse\\JAVA\\untitled2\\src\\jdbc\\config1.properties"),  "数据库配置文件");
    }

    public static void main(String[] args) {
        try {
            new Pro().storePropertiesToHardFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
